dim app,doc,v
set app=application
set doc=app.activedocument
set v = doc.ActiveView
dim dict
Set dict = CreateObject("Scripting.Dictionary")
main
set dict =nothing

sub Main
	dim ws 
	dim regPath,varName
	dim EnvRoot
	set ws = CreateObject("WScript.Shell")
	varName = "PADS_SHORTCUT_ROOT"
	regPath ="HKEY_CURRENT_USER\Software\MyApp\PADS\" & varName
	EnvRoot = ws.RegRead(regPath)
	dim conffile
	conffile = EnvRoot & "\config\netclass_color.txt"
	dim fso,fo,freadall
	set fso = createobject("scripting.filesystemobject")
	if fso.fileExists(conffile) then
		set fo = fso.opentextfile(conffile)
		freadall = fo.readall
		fo.close
		set fo = nothing
		
		freadall = replace(freadall,chr(13),"")
		dim s,ls,i
		s = split(freadall,chr(10))
		ls = ubound(s)-lbound(s)+1
		
		dim cs,lcs
		for i= 0 to ls-1
			s(i)=trim(s(i))
			cs = split(s(i),chr(9))
			lcs = ubound(cs)-lbound(cs)+1
			if lcs =2 then
				dict.Add cs(0), cs(1)			
			end if				
		next

		
		dim ncount
		dim objs,obj
		dim ncs,nc
		set ncs = doc.NetClasses		
		for each nc in ncs	
			
			For Each okey In dict'.Keys	
				'outputstr = key & " = " & dict(key) 
				'msgbox outputstr
				if nc.name = okey then
					doc.SelectObjects ppcbObjectTypeAll, "*", False 
					set objs = nc.nets
					ncount = objs.count
					for each ob in objs			
						doc.SelectObjects(2,ob.name,True) 
					next	
					'msgbox dict(okey)
					call ColorSelectedNetClasses(dict(okey) )
					exit for
				end if	
			next
		next	
	else
		msgbox "missing config file~"
	end if	
end Sub

sub ColorSelectedNetClasses(selectColorIndex)		
	dim ncount
	dim objs
	set objs = doc.getobjects(2,,true)
	ncount = objs.count
		
	dim ostr
	ostr = "Application.ExecuteCommand(""View Nets"")" & chr(13) & chr(10)
	ostr = ostr & "ViewNetsDlg.SelectBy = ""Selected""" & chr(13) & chr(10)
	for i= 0 to ncount-1	
		ostr = ostr & "ViewNetsDlg.ViewList.Selected("& cint(i) &") = true" & chr(13) & chr(10)
		ostr = ostr & "ViewNetsDlg.ColorsButtonPad.SetActive ("& cint(selectColorIndex) &")" & chr(13) & chr(10)
	next			
	ostr = ostr & vbcrlf & "ViewNetsDlg.Ok.Click()"			
			
	dim tmpfile
	tmpfile = doc.path & "\tmp1.mcr"
	Dim fso,fw
	Set fso = CreateObject("scripting.filesystemobject")
	Set fw = fso.CreateTextFile(tmpfile,True)
	fw.Write ostr
	fw.close
	Set fw = Nothing	
	Set fso = Nothing			
	application.RunMacro(tmpfile,"")
end sub